<template>
  <div class="ticketContainer">
    <div class="ticket-title">{{ ticketInfo.title }}</div>
    <div class="ticket-header">
      <span
        :class="spanSelect == 0 ? 'selected' : 'notSelected'"
        @click="changeSelect(0)"
        >{{ ticketInfo.homeTitleMonths }}</span
      >
      <span
        :class="spanSelect == 1 ? 'selected' : 'notSelected'"
        @click="changeSelect(1)"
        >{{ ticketInfo.homeTitleToday }}</span
      >
    </div>
    <div class="ticket-imgs">
      <a
        class="ticket-imgs_item"
        v-for="(item3, index3) in tickets"
        :key="index3"
        @click="goDetail(item3)"
      >
        <div class="item-img">
          <div class="body-img">
            <!-- 使用懒加载 存在一些小问题 切换数据源时图片不会及时刷新 -->
            <img v-lazy="item3.img" :key="item3.img" />
            <!-- <img :src="item3.img" alt=""/> -->
          </div>
          <div :class="item3.fromTo ? 'body-descript' : 'body-descriptNone'">
            <p>{{ item3.fromTo }}</p>
            <p>{{ item3.timer }}</p>
          </div>
        </div>
        <div class="item-main">
          <div class="item-words">
            <div class="item-words_main">{{ item3.descript }}</div>
            <div class="item-words-sub">{{ item3.subtitle }}</div>
          </div>
          <div class="item-price">{{ item3.price ? "￥" + item3.price : "" }}</div>
        </div>
      </a>
    </div>
    <div class="getMore">
      <a href="">
        <span>{{ ticketInfo.more }}</span>
        <span class="iconfont">&#xe629;</span>
      </a>
    </div>
  </div>
</template>

<script>
import { reactive, toRefs } from "@vue/reactivity";
import { useRouter } from "vue-router";
export default {
  props: {
    ticketInfo: {
      type: Object,
    },
  },
  setup(props) {
    const state = reactive({
      spanSelect: 0,
      ticketInfo: props.ticketInfo,
      tickets: props.ticketInfo.tickets,
    });
    const router = useRouter();
    function changeSelect(e) {
      // 点击修改spanSelect的值，从而修改样式
      state.spanSelect = e;
      if (e == 0) {
        state.tickets = props.ticketInfo.tickets;
      }
      if (e == 1) {
        state.tickets = props.ticketInfo.ticketsMore;
      }
    }
    function goDetail(e) {
      // console.log("点击商品", e.id);
      router.push({ path: "/qunar/detail", query: { id: e.id } });
    }
    return {
      ...toRefs(state),
      changeSelect,
      goDetail,
    };
  },
  methods: {},
};
</script>
<style scoped>
.ticket-title {
  color: #26282a;
  font-weight: 700;
  font-size: 0.768rem;
  margin-left: 0.16rem;
  margin-bottom: 0.08rem;
  margin-top: 0.08rem;
  padding-left: 0.4267rem;
}
.ticket-header {
  margin-bottom: 0.2987rem;
  margin-top: 0.4267rem;
  padding-left: 0.3413rem;
}
.selected {
  display: inline-block;
  background: #17c0c8;
  color: #fff;
  margin-left: 0.2133rem;
  border-radius: 0.128rem;
  border: 0.0427rem solid #17c0c8;
  font-size: 0.4267rem;
  padding: 0 0.4267rem;
  height: 1.28rem;
  box-sizing: border-box;
  font-weight: 650;
  text-align: center;
  line-height: 1.28rem;
}

.notSelected {
  display: inline-block;
  background: #fff;
  color: #000;
  margin-left: 0.2133rem;
  border-radius: 0.128rem;
  border: 0.0427rem solid #e3e3e3;
  font-size: 0.4267rem;
  padding: 0 0.4267rem;
  height: 1.28rem;
  box-sizing: border-box;
  font-weight: 450;
  text-align: center;
  line-height: 1.28rem;
}
.ticket-imgs {
  display: flex;
  flex-wrap: wrap;
  padding: 0.4267rem;
}
.ticket-imgs > a:nth-child(even) {
  margin-left: 0.2133rem;
}
.ticket-imgs_item {
  width: 49%;
  text-decoration: none;
}
.item-img {
  width: 100%;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}
.body-img {
  width: 100%;
}
.body-img img {
  width: 100%;
  height: auto;
  border-radius: 0.2133rem;
}
.body-descript {
  position: absolute;
  bottom: 0.2133rem;
  background: #161212;
  padding: 0.4267rem 0.4267rem 0 0.4267rem;
  font-size: 0.5547rem;
}
.body-descriptNone {
  display: none;
}
.body-descript > p:nth-child(1) {
  color: #fff;
  margin: 0;
}
.body-descript > p:nth-child(2) {
  color: #ffde00;
  margin: 0;
  padding: 0.0853rem 0;
}
.item-words_main {
  color: #161212;
  font-size: 0.5973rem;
  padding: 0.0853rem 0;
}
.item-words-sub {
  font-size: 0.5547rem;
  color: #6b6d6b;
  padding: 0.0853rem 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.item-price {
  color: #ff7400;
  font-weight: 600;
  padding: 0.0853rem 0;
}

.item-main {
  padding: 0.3413rem;
}
.getMore {
  width: 14.5067rem;
  height: 1.7067rem;
  border: 0.0213rem solid #00d0d4;
  margin: 0.64rem;
  /* text-align: center; */
  border-radius: 0.1707rem;
  color: #00d0d4;
  display: flex;
  justify-content: center;
  align-content: center;
}
.getMore a {
  text-decoration: none;
  line-height: 1.7067rem;
  color: #00d0d4;
  font-size: 0.5973rem;
}
.getMore .iconfont {
  font-size: 0.5973rem;
}
</style>
